package com.ruoyi.web.controller.tongban;

import java.util.List;

import com.ruoyi.tongban.domain.TInstitution;
import org.apache.poi.poifs.property.Child;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tongban.domain.InsChild;
import com.ruoyi.tongban.service.IInsChildService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 孩子Controller
 * 
 * @author ruoyi
 * @date 2021-04-21
 */
@RestController
@RequestMapping("/tongban/child")
public class InsChildController extends BaseController
{
    @Autowired
    private IInsChildService insChildService;

    /**
     * 查询孩子列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:child:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsChild insChild)
    {
        startPage();
        List<InsChild> list = insChildService.selectInsChildList(insChild);
        return getDataTable(list);
    }

    /**
     * 根据班级id查询孩子列表
     * @param id 班级id
     * @return 孩子列表
     */
    @GetMapping("/listInstitutionChild")
    public AjaxResult listInstitutionChild(@RequestParam Long id){
        List<InsChild> list = insChildService.institutionChild(id);
        return AjaxResult.success(list);
    }

    /**
     * 导出孩子列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:child:export')")
    @Log(title = "孩子", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(InsChild insChild)
    {
        List<InsChild> list = insChildService.selectInsChildList(insChild);
        ExcelUtil<InsChild> util = new ExcelUtil<InsChild>(InsChild.class);
        return util.exportExcel(list, "child");
    }

    /**
     * 获取孩子详细信息
     */
    @PreAuthorize("@ss.hasPermi('tongban:child:query')")
    @GetMapping(value = "/{childId}")
    public AjaxResult getInfo(@PathVariable("childId") Long childId)
    {
        return AjaxResult.success(insChildService.selectInsChildById(childId));
    }

    /**
     * 新增孩子
     */
    @PreAuthorize("@ss.hasPermi('tongban:child:add')")
    @Log(title = "孩子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsChild insChild)
    {
        return toAjax(insChildService.insertInsChild(insChild));
    }

    /**
     * 修改孩子
     */
    @PreAuthorize("@ss.hasPermi('tongban:child:edit')")
    @Log(title = "孩子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsChild insChild)
    {
        return toAjax(insChildService.updateInsChild(insChild));
    }

    /**
     * 删除孩子
     */
    @PreAuthorize("@ss.hasPermi('tongban:child:remove')")
    @Log(title = "孩子", businessType = BusinessType.DELETE)
	@DeleteMapping("/{childIds}")
    public AjaxResult remove(@PathVariable Long[] childIds)
    {
        return toAjax(insChildService.deleteInsChildByIds(childIds));
    }
}
